package com.hujing.springsource.a14;

import org.springframework.cglib.core.Signature;

import java.lang.reflect.InvocationTargetException;

public class TargetFastClass {

    static Signature s0 = new Signature("save","()V");
    static Signature s1 = new Signature("save","(I)V");
    static Signature s2 = new Signature("save","(L)V");

    public int getIndex(Signature signature){
        if (s0.equals(signature)){
            return 0;
        }else if (s1.equals(signature)){
            return 1;
        }else if (s2.equals(signature)){
            return 2;
        }
        throw new RuntimeException("无此方法");
    }

    public Object invoke(int index, Object obj, Object[] args) throws InvocationTargetException{
        Target target1 = (Target) obj;
        if (index == 0){
            target1.save();
            return null;
        }
        if (index == 1){
            target1.save((int)args[0]);
            return null;
        }
        if (index == 2){
            target1.save((long) args[0]);
            return null;
        }
        throw new RuntimeException("调用异常");
    }

}
